"""PyAudio Example: Play a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
# FILENAME = 'voice_data2/train/left/zsn-left6.wav'
# FILENAME = 'voice_data2/train/right/lm-right1.wav'
# FILENAME = r'D:\_const\large_data\audio\_many_files\direction_data_1st\test\lefts\cxz_left_0 (1).wav'
FILENAME = '/home/asuspei/large_data/audio/_many_files/direction_data_1st/test/lefts/cxz_left_0 (1).wav'


def player(filename=FILENAME):
    wf = wave.open(filename, 'rb')

    p = pyaudio.PyAudio()

    stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                    channels=wf.getnchannels(),
                    rate=wf.getframerate(),
                    output=True)

    data = wf.readframes(CHUNK)

    while data != b'':
        stream.write(data)
        data = wf.readframes(CHUNK)

    stream.stop_stream()
    stream.close()

    p.terminate()


player(FILENAME)
